package com.xusheng.cli.common.base;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import icu.mhb.mybatisplus.plugln.base.service.impl.JoinServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jy
 * @since 2021-11-15 15:09
 */
public class MyServiceImpl<M extends MyBaseMapper<T>, T extends BaseEntity> extends JoinServiceImpl<M, T> implements MyService<T> {

	/**
	 * 批量删除数据
	 *
	 * @param t      实体类
	 * @param idList id 集合
	 * @return 执行结果
	 * @author jy
	 * @since 2021/11/15 14:05
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean batchDelete(List<Long> idList, T t) {
		return SqlHelper.retBool(baseMapper.deleteWithFill(t, new LambdaQueryWrapper<>(t)
				.in(T::getId, idList)));
	}

	/**
	 * 删除数据
	 *
	 * @param t       实体类
	 * @param wrapper 筛选条件
	 * @return 执行结果
	 * @author jy
	 * @since 2021/11/15 14:05
	 */
	@Override
	public boolean deleteWithFill(T t, Wrapper<T> wrapper) {
		return SqlHelper.retBool(baseMapper.deleteWithFill(t, wrapper));
	}

}
